const domainName = getApp().globalData.domainName
const header = {'content-type':'application/x-www-form-urlencoded'}
const dataType = 'json'
const method = 'POST'
const responseType = 'text'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page_no:0,
    recruit_list:[],
  },

  contact(){
    wx.navigateTo({
      url: '/pages/contact_admin/contact_admin',
    })
  },

  // 查看招聘信息详情
  view_details(e){
    let index = e.currentTarget.id
    let recruitment_id = this.data.recruit_list[index].recruitment_id
    wx.navigateTo({
      url: '/pages/recruitment/recruitment_show/recruitment_show?recruitment_id=' + recruitment_id,
    })
  },

  // 加载招聘信息列表
  load_recruitment_list(status,page_no){
    wx.showLoading({
      title: '网络连接中',
      mask: false,
    })
    if(page_no==0){
      this.setData({
        recruit_list:[],
        page_no:0,
      })
    }
    wx.request({
      url: domainName + '/load_recruitment_list',
      data: {
        status:status,
        page_no:page_no,
      },
      dataType: dataType,
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      header: header,
      method: method,
      responseType: responseType,
      timeout: 0,
      success: res => {
        wx.hideLoading()
        let recruit_list = res.data.recruit_list
        if(recruit_list.length>0){
          this.setData({
            recruit_list:this.data.recruit_list.concat(recruit_list),
            page_no:this.data.page_no + 1,
          })
        }else{
          this.setData({
            no_more:true
          })
        }
      },
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let status = 4  // 4-已通过
    this.setData({
      windowWidth : wx.getSystemInfoSync().windowWidth,
      status:status,
    })
    this.load_recruitment_list(status,0)
    wx.stopPullDownRefresh()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onLoad()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.load_recruitment_list(this.data.status,this.data.page_no)
  },

})